package com.pedro.streamer.view;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.pedro.streamer.R;
import com.pedro.streamer.adapter.FilterSourceTabAdapter;
import com.pedro.streamer.manager.MediaPlayerClient;
import com.pedro.streamer.utils.RecyclerViewSpacesItemDecoration;

import java.util.ArrayList;
import java.util.HashMap;

public class FilterSourceView extends ConstraintLayout {

    private String TAG = "com.pedro.streamer";
    private RecyclerView recyclerView;
    private TextView closeText;
    private FilterSourceTabAdapter filterSourceTabAdapter;

    private CameraLensControlView cameraLensControlView;
    private CameraStickerControlView cameraStickerControlView;
    private CameraFilterControlView cameraFilterControlView;
    private Context mContext;
    public FilterSourceView(@NonNull Context context) {
        super(context);
        mContext = context;

    }


    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();

        initView();
    }

    private void initView() {
        recyclerView = findViewById(R.id.filter_source_recycle);

        closeText = findViewById(R.id.close_text);
        this.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });

        cameraLensControlView = findViewById(R.id.camera_lens_control_layout);
        cameraStickerControlView = findViewById(R.id.camera_sticker_control_layout);
        cameraFilterControlView = findViewById(R.id.camera_filter_control_layout);
        closeText.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View view) {
               setVisibility(View.GONE);
            }
        });

        ArrayList list = new ArrayList<>();
        list.add("运镜");
        list.add("滤镜");
        list.add("贴图");

        filterSourceTabAdapter = new FilterSourceTabAdapter();
        filterSourceTabAdapter.setClickListener(new FilterSourceTabAdapter.OnTextClickListener() {
            @Override
            public void onTextClick(int position) {
                if (position == 0){
                    cameraLensControlView.setVisibility(View.VISIBLE);
                    cameraFilterControlView.setVisibility(View.GONE);
                    cameraStickerControlView.setVisibility(View.GONE);
                }else if (position == 1) {
                    cameraLensControlView.setVisibility(View.GONE);
                    cameraFilterControlView.setVisibility(View.VISIBLE);
                    cameraStickerControlView.setVisibility(View.GONE);
                } else {
                    cameraLensControlView.setVisibility(View.GONE);
                    cameraFilterControlView.setVisibility(View.GONE);
                    cameraStickerControlView.setVisibility(View.VISIBLE);
                }

            }
        });
        filterSourceTabAdapter.setList(list);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext);
        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        HashMap<String, Integer> stringIntegerHashMap = new HashMap<>();
        stringIntegerHashMap.put(RecyclerViewSpacesItemDecoration.BOTTOM_DECORATION, 16);//左间距
        recyclerView.addItemDecoration(new RecyclerViewSpacesItemDecoration(stringIntegerHashMap));
        recyclerView.setLayoutManager(linearLayoutManager);
        recyclerView.setAdapter(filterSourceTabAdapter);
    }


    public void reloadView(){

        if (cameraFilterControlView != null){
            cameraFilterControlView.reloadView();
        }

        if (cameraLensControlView != null){
            cameraLensControlView.reloadView();
        }

        if (cameraStickerControlView != null){
            cameraStickerControlView.reloadView();
        }


    }
    public FilterSourceView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }
}
